<?php if (($section == "comments") || ($section == "view_comments")) { ?>
<div id="comment-preview">
<h1>Assignment <?php echo $row_assignments['mid'].".".$row_assignments['assign_num']; ?>: <?php echo $row_assignments['assign_title']; ?></h1>
<?php echo $row_assignments['assign_overview']; ?>
<h2>Procedure</h2>
<?php echo $row_assignments['assign_procedure']; ?>
</div>
<?php } // end if ($section == "comments") 
else 
{ 
?>
<h3>Module <?php echo $row_modules['mid']; ?> Assignments</h3>
<?php if ($modal_window != "true") { ?>
<div class="stacked">
<span class="icon"><img src="images/page_add.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?section=proposal_titles&action=add&dbTable=assignments&cid=<?php echo $cid; ?>','mid','<?php echo $row_modules['mid']; ?>','Are you sure you want to add an assignment to Module <?php echo $row_modules['mid']; ?>?')">Add an Assignment to Module <?php echo $row_modules['mid']; ?>?</a>
</div>
<?php } ?>
<table class="dataTable">
    <tr style="background-color: <?php echo $color1; ?>">
        <th class="data" width="10%">#</th>
        <th>Title</th>
        <th class="data" width="10%">ID/Reviewer<br />Comments?</th>
        <th class="data" width="10%">Changes<br />Needed?</th>
        <th class="data" width="10%">Current Version</th>
        <th class="data" width="10%">Other Versions</th>
        <th class="data" width="23%">Actions</th>
    </tr>
	<?php 		
			do { $d[] = $row_assignments['assign_num']; } while ($row_assignments = mysql_fetch_assoc($assignments));
			sort($d);
			foreach (array_unique($d) as $value1) {
				$query_assignment_loop = sprintf("SELECT * FROM assignments WHERE cid='%s' AND mid='%s' AND assign_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $row_modules['mid'], $value1);
				$assignment_loop = mysql_query($query_assignment_loop, $connection) or die(mysql_error());
				$row_assignment_loop = mysql_fetch_assoc($assignment_loop);
				$totalRows_assignment_loop = mysql_num_rows($assignment_loop);
				
				$query_assignment_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='assignments' AND rid='%s'", $cid, $row_assignment_loop['id']);
				$assignment_comments = mysql_query($query_assignment_comments, $connection) or die(mysql_error());
				$row_assignment_comments = mysql_fetch_assoc($assignment_comments);
				$totalRows_assignment_comments = mysql_num_rows($assignment_comments);
				
				if ($totalRows_assignment_loop > 0) { ?>
                
	<tr style="background-color: <?php echo $color; ?>">
		<td class="data" nowrap="nowrap">Assignment <?php echo $row_modules['mid'].".".$row_assignment_loop['assign_num']; ?>:<?php if ($row_assignment_loop['assign_points'] != "") echo "<br>(".$row_assignment_loop['assign_points']." points)"; ?></td>
       	<td class="data"><?php echo display_content($row_assignment_loop['id'],"assignments"); $check1 = ltrim($row_assignment_loop['assign_title'],"Course Project -"); $check2 = ltrim($row_assignment_loop['assign_title'],"Discussion -"); if (($check1 == "") || ($check2 == "")) { ?><span class="icon"><img src="images/exclamation.png" border="0" align="absmiddle" /></span>No Title Entered<?php } ?></td>
        <!-- Comments -->
        <td class="data">
        <?php if ($totalRows_assignment_comments > 0) echo "<div class='stacked'><span class='icon'><img src='images/comment.png' align='absmiddle' border='0'></span>Yes - <a id='modal_window_link' href='index.php?section=view_comments&amp;dbTable=assignments&amp;cid=".$cid."&amp;id=".$row_assignment_loop['id']."&amp;modal_window=true' title='View ID Comments'>View</a></div>"; else echo "<div class='stacked'><span class='icon'><img src='images/comment_fade.png' align='absmiddle' border='0'></span>No</div>"; if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&action=add&amp;cid=".$cid."&amp;dbTable=assignments&amp;id=".$row_assignment_loop['id']."&amp;modal_window=true'>Add Comment</a></div>"; ?>
        </td>
        
        
        <!-- Changes Needed -->
        <td class="data"><?php  if ($row_assignment_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No";  ?></td>
        
        <!-- Current Versions -->
        <td class="data"><?php if ($row_assignment_loop['vid'] != "") echo $row_assignment_loop['vid']; else echo "<div class='stacked'><span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>No content</div>"; ?></td>
       
        <!-- Other Versions -->
        <td class="data">
        
        <?php 
		// Get the other versions of the assignment, if any
			$query_versions = sprintf("SELECT * FROM assignments WHERE cid='%s' AND mid='%s' AND assign_num='%s' ORDER BY vid", $cid, $row_modules['mid'], $row_assignment_loop['assign_num']);
			$versions = mysql_query($query_versions, $connection) or die(mysql_error());
			$row_versions = mysql_fetch_assoc($versions);
			$totalRows_versions = mysql_num_rows($versions);
			//echo $totalRows_assign_versions;
			
			if ($totalRows_versions > 1) {
									do 	{ 
										if (($totalRows_versions > 0) && ($row_versions['vid'] != $row_assignment_loop['vid'])) echo "<a id='modal_window_link' href='index.php?section=view_course&amp;action=review&amp;go=assignment&amp;cid=".$cid."&amp;id=".$row_versions['id']."&amp;modal_window=true'>".$row_versions['vid']."</a>&nbsp;&nbsp;"; 
										} while ($row_versions = mysql_fetch_assoc($versions));
								} else echo "None";
		?>
        
        </td>
        
        <!-- Actions -->
        <td class="data">
        <?php if ($modal_window != "true") { ?>
        <div class="stacked">
        <span class="icon"><img src="images/page_edit.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=module_assignment&amp;action=<?php if (($row_assignment_loop['assign_overview'] == "") && ($row_assignment_loop['assign_procedure'] == "")) echo "add"; else echo "edit"; ?>&amp;go=<?php if (($row_assignment_loop['assign_overview'] != "") && ($row_assignment_loop['assign_procedure'] == "")) echo "draft"; else echo "make-changes"; ?>&amp;view=course_detail&amp;dbTable=assignments&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $row_assignment_loop['mid']; ?>&amp;vid=<?php if ($row_assignment_loop['vid'] != "") echo $row_assignment_loop['vid']; else echo "default"; ?>&amp;id=<?php echo $row_assignment_loop['id']; ?>&amp;modal_window=true"><?php if (($row_assignment_loop['assign_overview'] == "") && ($row_assignment_loop['assign_procedure'] == "")) echo "Add"; else echo "Make Changes to"; ?>  Assignment Content</a>
		</div>
		<?php if ($row_assignment_loop['assign_num'] > "1") { ?>
        <div class="stacked">
        <span class="icon"><img src="images/bin_closed.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?action=delete&dbTable=assignments','id','<?php echo $row_assignment_loop['id']; ?>','Are you sure want to delete Module <?php echo $row_modules['mid']; ?>, Assignment <?php echo $row_modules['mid'].".".$row_assignment_loop['assign_num']; ?>?')">Delete Assignment</a>
		</div>
		<?php } ?>
        <?php } else echo "&nbsp;"; ?>
        </td>
	</tr>
    <?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
	<?php } 
	} ?>
</table>
<?php } ?>